using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class ProductAttributeMap : EntityTypeConfiguration<ProductAttribute>
    {
        public ProductAttributeMap()
        {
            // Primary Key
            this.HasKey(t => t.ProductAttributeId);

            // Properties
            this.Property(t => t.ProductAttributeId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.AttributeName)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.AttributeValue)
                .IsRequired()
                .HasMaxLength(40);

            // Table & Column Mappings
            this.ToTable("ProductAttribute");
            this.Property(t => t.ProductAttributeId).HasColumnName("ProductAttributeId");
            this.Property(t => t.AttributeName).HasColumnName("AttributeName");
            this.Property(t => t.AttributeValue).HasColumnName("AttributeValue");
            this.Property(t => t.ProductId).HasColumnName("ProductId");

            // Relationships
            this.HasRequired(t => t.Product)
                .WithMany(t => t.ProductAttributes)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
